import React, { useState,useEffect } from 'react';
import Home from './child/home';
import Useer from './child/useer';
import Menus from './child/menus';
import { async_list } from '../store/crimsSlice';
import Bu from './child/bu';
import Gang from './child/gang';
import {Switch,Route,Redirect} from "react-router-dom"
import {useDispatch} from "react-redux"
import {
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  UploadOutlined,
  UserOutlined,
  VideoCameraOutlined,
  SkinOutlined,
  TeamOutlined,
  SaveOutlined
} from '@ant-design/icons';
import { Button, Layout, Menu, theme } from 'antd';
import Jue from './child/jue';
const { Header, Sider, Content } = Layout;
const Admin = (props) => {
    let dispatch=useDispatch()
    useEffect(()=>{
        dispatch(async_list())
    })
  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();
  return (
    <Layout>
      <Sider trigger={null} collapsible collapsed={collapsed}>
        <div className="demo-logo-vertical" />
        <Menu
          theme="dark"
          mode="inline"
          defaultOpenKeys={['',props.location.pathname]}
          defaultSelectedKeys={[props.location.pathname]}
          items={[
            {
              key: '/admin/home',
              icon: <UserOutlined />,
              label: '首页',
            },
            {
              key: '',
              icon: <VideoCameraOutlined />,
              label: '系统管理',
              children:[
                    {
              key: '/admin/useer',
              icon: <TeamOutlined />,
              label: '用户管理',
            },
                        {
              key: '/admin/jue',
              icon:  <SkinOutlined />,
              label: '角色管理',
             
            },
                        {
              key: '/admin/menus',
              icon: <MenuUnfoldOutlined />,
              label: '菜单管理',
            },
                        {
              key: '/admin/bu',
              icon: <SaveOutlined />,
              label: '部门管理',
            },
                        {
              key: '/admin/gang',
              icon: <UploadOutlined />,
              label: '岗位管理',
            },
              ]
            },
        
          ]}
          onSelect={(obj)=>{
            props.history.push(obj.key)
          }}
        />
      </Sider>
      <Layout>
        <Header style={{ padding: 0, background: colorBgContainer }}>
          <Button
            type="text"
            icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
            onClick={() => setCollapsed(!collapsed)}
            style={{
              fontSize: '16px',
              width: 64,
              height: 64,
            }}
          />
        </Header>
        <Content
          style={{
            margin: '24px 16px',
            padding: 24,
            minHeight: 280,
            background: colorBgContainer,
            borderRadius: borderRadiusLG,
          }}
        >
        <Switch>
            <Route path='/admin/home' component={Home}></Route>
      <Route path='/admin/useer' component={Useer}></Route>
            <Route path='/admin/jue' component={Jue}></Route>
            <Route path='/admin/menus' component={Menus}></Route>
            <Route path='/admin/bu' component={Bu}></Route>
            <Route path='/admin/gang' component={Gang}></Route>
            <Redirect from='' to='/admin/home'></Redirect>
        </Switch>
        </Content>
      </Layout>
    </Layout>
  );
};
export default Admin;